package com.zixi.beverage_order.controller.customer;


import com.zixi.beverage_order.pojo.Customer;
import com.zixi.beverage_order.service.customer.WxLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/wx")
public class WxLoginController {
//    控制微信登录和拉取用户信息的控制类
    @Autowired
    private WxLoginService wxLoginService;

    @PostMapping("/login")
    @ResponseBody
//    登录查看是否有此用户的请求
    public Customer wxLogin(@RequestParam("code") String code) {
        return wxLoginService.Code2OpenId(code);
    }


    @PostMapping("/getinfo")
    @ResponseBody
//    未存在此用户向后端存储昵称和头像的请求
    public Customer wxGetUserProfile(@RequestParam("nickName") String nickName,
                                    @RequestParam("avatarUrl") String avatarUrl) {
        return wxLoginService.SetCustomerInfo(nickName,avatarUrl);
    }
}
